package com.qianfeng.smartdevices.controller;

import com.qianfeng.smartdevices.annotations.AopLogAnnotation;
import com.qianfeng.smartdevices.dto.R;
import com.qianfeng.smartdevices.pojo.UserRole;
import com.qianfeng.smartdevices.service.UserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/userroles")
public class UserColeController {

    private UserRoleService userRoleService;
    @Autowired
    public void setUserRoleService(UserRoleService userRoleService) {
        this.userRoleService = userRoleService;
    }
    @PostMapping("/userroles")
    @AopLogAnnotation("用户角色表添加")
    public R addUserRole(@RequestBody UserRole userRole){
        userRoleService.addUserRole(userRole);
        return R.setOK();
    }

    @GetMapping("/userroles")
    @AopLogAnnotation("用户角色查询")
    public R findAllUserRole(){
        List<UserRole> allUserRole = userRoleService.findAllUserRole();
        return R.setOK(allUserRole);
    }
    @PutMapping("/userroles")
    @AopLogAnnotation("用户角色更新")
    public R updateUserRole(@RequestParam Long userId,@RequestParam Long roleId,@RequestParam Long uid,@RequestParam Long rid){
        userRoleService.updateUserRole(userId,roleId,uid,rid);
        return R.setOK();
    }
}
